package com.haoniu.module.service.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.haoniu.common.utils.MyHashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.haoniu.module.mapper.UserMapper;
import com.haoniu.module.domain.database.User;
import com.haoniu.module.service.UserService;
import com.haoniu.common.support.Convert;

import javax.annotation.Resource;

/**
 * 用户 服务层实现
 *
 * @author admin
 * @date 2019-01-24
 */
@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    /**
     * 查询用户信息
     *
     * @param id 用户ID
     * @return 用户信息
     */
    @Override
    public User selectUserById(Integer id) {
        return userMapper.selectUserById(id);
    }

    /**
     * 查询用户列表
     *
     * @param user 用户信息
     * @return 用户集合
     */
    @Override
    public List<User> selectUserList(User user) {
        return userMapper.selectUserList(user);
    }

    /**
     * 新增用户
     *
     * @param user 用户信息
     * @return 结果
     */
    @Override
    public int insertUser(User user) {
        return userMapper.insertUser(user);
    }

    /**
     * 修改用户
     *
     * @param user 用户信息
     * @return 结果
     */
    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    /**
     * 删除用户对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteUserByIds(String ids) {
        return userMapper.deleteUserByIds(Convert.toStrArray(ids));
    }

    @Override
    public int deleteUserById(Integer id) {
        return userMapper.deleteUserById(id);
    }


    @Override
    public int recoverUserById(Integer id) {
        return userMapper.recoverUserById(id);
    }

    @Override
    public int recoverUserByIds(String ids) {
        return userMapper.recoverUserByIds(Convert.toStrArray(ids));
    }

    @Override
    public User selectUserByPhone(String phone) {
        return userMapper.selectUserByPhone(phone);
    }

    @Override
    public User selectUserByNickName(String nickName) {
        return userMapper.selectUserByNickName(nickName);
    }

    @Override
    public List<User> findAllRoomBoss() {
        return userMapper.findAllRoomBoss();
    }

    @Override
    public List<User> findAllOrdinary() {
        return userMapper.findAllOrdinary();
    }

    @Override
    public int setUpRoomBoss(Integer userId) {
        return userMapper.setUpRoomBoss(userId);
    }

    @Override
    public int setUpOrdinary(Integer userId) {
        return userMapper.setUpOrdinary(userId);
    }

    @Override
    public List<User> findNoticeUser() {
        return userMapper.findNoticeUser();
    }

    @Override
    public List<Integer> findAllUser() {
        return userMapper.findAllUser();
    }

    @Override
    public List<Integer> findPingTaiUser() {
        return userMapper.findPingTaiUser();
    }

    /**
     * 后台首页显示
     *
     * @return
     */
    public Map getMoneyTotal() {
        // 平台充值总金额
        BigDecimal totalPtRechargeMoney = userMapper.totalPtRechargeMoney();
        // 用户充值总金额
        BigDecimal totalUserRechargeMoney = userMapper.totalUserRechargeMoney();
        // 提现总金额
        BigDecimal totalWithdrawMoney = userMapper.totalWithdrawMoney();
        // 平台总佣金
        BigDecimal totalAwardMoney = userMapper.totalAwardMoney();
        // 免死用户抢包金额
        BigDecimal totalPtUserMoney = userMapper.totalPtUserMoney();
        // 机器人抢包金额
        BigDecimal totalRobotMoney = userMapper.totalRobotMoney();
        // 平台所有用户余额总和
        BigDecimal totalUserMoney = userMapper.totalUserMoney();
        return new MyHashMap<>()
                .add("平台充值总金额:", totalPtRechargeMoney)
                .add("用户充值总金额:", totalUserRechargeMoney)
                .add("提现总金额:", totalWithdrawMoney)
                .add("平台总佣金:", totalAwardMoney)
                .add("免死用户抢包金额:", totalPtUserMoney)
                .add("机器人抢包金额:", totalRobotMoney)
                .add("平台所有用户余额总和:", totalUserMoney);
    }

}
